#include<iostream>
using namespace std;
class Date {
	friend ostream& operator<<(ostream& out, Date& D);
private:
	int year;
	int month;
	int day;
public:
	Date(int y = 2004, int m = 1, int d = 1) :year(y), month(m), day(d) {

	}
	bool isLeapYear() {
		return year % 400 == 0 || year % 100 != 0 && year % 4 == 0;
	}
	Date& operator++() {
		int p[12] = { 31,28,31,30,31,30,31,31,30,31,30,31 };
		if (isLeapYear()) {
			p[1]++;
		}
		day++;
		if (day > p[month - 1]) {
			month++;
			if (month > 12) {
				month = 1;
				year++;
			}
			day = 1;
		}
		return *this;
	}
};
ostream& operator<<(ostream& out, Date& D) {
	out << D.year << '-';
	if (D.month < 10) {
		out << '0' << D.month;
	}
	else {
		out << D.month;
	}
	out << '-';
	if (D.day < 10) {
		out << '0' << D.day;
	}
	else {
		out << D.day;
	}
	out << endl;
	return out;
}
int main() {
	int m;
	cin >> m;
	int year, month, day;
	int n;
	while (m) {
		cin >> year >> month >> day >> n;
		Date D(year, month, day);
		while (n) {
			++D;
			n--;
		}
		cout << D;
		m--;
	}

	return 0;
}